package com.ruoyi.mdkt.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.mdkt.entity.WXAuth;
import com.ruoyi.mdkt.entity.vo.CodeVo;
import com.ruoyi.mdkt.entity.vo.RegistVo;
import com.ruoyi.mdkt.service.UserLoginService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@CrossOrigin

@Api(tags = "登录管理")
@RestController
@RequestMapping("/mdkt/userLogin")
public class UserLoginController extends BaseController {


    //    @ApiOperation("登录")
//    @PostMapping("login")
//    public R login(@RequestBody String username ,@RequestBody String password){
//        return R.ok("token");
//    }
    @Autowired
    private UserLoginService userLoginService;

    @PostMapping("/getToken")
    public R getSessionId(@RequestBody String code) {
        return userLoginService.getSessionId(code);
    }

    @PostMapping("/authLogin")
    public R authLogin(@RequestBody WXAuth wxAuth) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
        return userLoginService.authLogin(wxAuth);
    }

    @PostMapping("/regist")
    public R regist(@RequestBody RegistVo registVo){
        return userLoginService.regist(registVo,103L);
    }

}
